<?php

class Account extends Admin_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Default function
     */
    public function index()
    {
        //nothing
    }

    /**
     * Process login
     */
    public function login()
    {
        //Disable layout
        $this->disable_layout();
        
        $post = $this->input->post(null, true);
        
        if (!empty($post))
        {
            if (empty($post['email']) || empty($post['password']))
            {
                $this->session->set_flashdata('error_message', 'Vui lòng điền email và password!');
                redirect('/backend/account/login');
            }
            
            $post['remember'] = isset($post['remember']) ? (bool) $post['remember'] : false;

            $is_success = $this->auth->login($post['email'], $post['password'], $post['remember']);

            if (!$is_success)
            {
                $this->session->set_flashdata('error_message', 'Email hoặc password không đúng!');
                redirect('/backend/account/login');
            }            
            
            redirect('/backend');
        }
        
        if ($this->auth->is_logged_in())
        {
            redirect('/backend');
        }
    }
    
    /**
     * Proccess logout
     */
    public function logout()
    {                
        //Disable layout
        $this->disable_layout();
        
        $this->auth->logout();
        
        redirect('/backend');
    }
    
    /**
     * Edit settings account
     */
    public function setting()
    {
        //Set layout title
        $this->layout_title = 'Thay đổi thông tin';
    }

}